package com.example.benefitcommunity.controller;

import com.example.benefitcommunity.entity.BcAddressList;
import com.example.benefitcommunity.service.BcAddressListService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.example.benefitcommunity.entity.Result;

import javax.annotation.Resource;

/**
 * 通讯录表(BcAddressList)表控制层
 *
 * @author makejava
 * @since 2025-08-06 15:07:26
 */
@Tag(name = "通讯录")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("bcAddressList")
public class BcAddressListController {
    /**
     * 服务对象
     */
    @Resource
    private BcAddressListService bcAddressListService;


    /**
     * 通过查询数据
     *
     * @param name     姓名
     * @param phone    类型
     * @param pagenum  页码
     * @param pagesize 页大小
     * @return 数据
     */
    @Operation(description = "通讯录查询")
    @GetMapping("list")
    public Result<Object> queryByAddressList(String name, String phone, Integer communityid, Integer pagenum, Integer pagesize) {
        return this.bcAddressListService.queryByAddressList(name, phone, communityid, pagenum, pagesize);
    }

    /**
     * 新增数据
     *
     * @param bcAddressList 实体
     * @return 新增结果
     */
    @Operation(description = "新增通讯录")
    @PostMapping("add")
    public Result<Object> add(@RequestBody BcAddressList bcAddressList) {
        return this.bcAddressListService.insert(bcAddressList);
    }

    /**
     * 编辑数据
     *
     * @param bcAddressList 实体
     * @return 编辑结果
     */
    @Operation(description = "编辑通讯录")
    @PutMapping("edit")
    public Result<Object> edit(@RequestBody BcAddressList bcAddressList) {
        return this.bcAddressListService.update(bcAddressList);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Operation(description = "删除通讯录")
    @DeleteMapping("delete")
    public Result<Object> deleteById(Integer[] id) {
        return this.bcAddressListService.deleteById(id);
    }

}

